package ioc13;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SomeBean implements ApplicationContextAware, BeanNameAware {
    private ApplicationContext ac;
    private String beanName;

    public void doSome(){
//        错，创建了新容器，而不是获得当前Bean所在的容器
//        ApplicationContext ac=new ClassPathXmlApplicationContext("ioc13/applicationContext.xml");

        System.out.println("SomeBean.doSome");
        System.out.println("doSome ac:"+ac);
        System.out.println("beanName:"+beanName);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("SomeBean.setApplicationContext");
        this.ac=applicationContext;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("SomeBean.setBeanName");
        this.beanName=beanName;
    }
}
